package com.springframework.core.service.impl;

import com.springframework.core.annotation.MyAutowired;
import com.springframework.core.annotation.MyComponent;
import com.springframework.core.annotation.MyScope;
import com.springframework.core.constant.ScopeType;
import com.springframework.core.context.BeanNameAware;
import com.springframework.core.context.InitializingBean;
import com.springframework.core.service.UserService;

@MyComponent //标记组件
@MyScope(ScopeType.SINGLETON) //标记单例
public class UserServiceImpl implements UserService, BeanNameAware, InitializingBean {

    @MyAutowired //自动注入，但是目前支持byName模式
    private OrderServiceImpl orderServiceImpl;

    private String beanName;

    @Override
    public void getOrderService(){
        System.out.println(orderServiceImpl);
    }


    @Override
    public void setBeanName(String beanName) {
        this.beanName=beanName;
    }

    @Override
    public void getBeanName() {
        System.out.println(beanName);
    }

    @Override
    public void afterPropertiesSet() {
        System.out.println("初始化Bean...");
    }

    @Override
    public String toString() {
        return "UserServiceImpl{" +
                "orderServiceImpl=" + orderServiceImpl +
                ", beanName='" + beanName + '\'' +
                '}';
    }
}
